/**
 * forum zhanjung
 */
package com.junhong.forum.backingbean;

import javax.ejb.EJB;

import com.junhong.auth.entity.User;
import com.junhong.auth.service.UserEjb;
import com.junhong.forum.common.Constants;
import com.junhong.forum.entity.AbstractEntity;
import com.junhong.forum.entity.ForumCategory;
import com.junhong.forum.exceptions.AuthorizationFailException;
import com.junhong.forum.service.CategoryServiceSingleton;

/**
 * designed for all the system management including category owner setup and
 * others
 * 
 * @author zhanjung
 * 
 */

@Deprecated
public class SystemManageBean extends AbstractBacking {

	private static final long			serialVersionUID	= -85049363231430233L;
	/* ------------instance Variable-------------- */
	@EJB
	private UserEjb						userEjb;
	@EJB
	private CategoryServiceSingleton	categorySingleton;

	/* -------------business logic----------------- */

	public String assignCategoryOwner(ForumCategory forumCategory) {
		String userId = forumCategory.getOwner().getUserId();
		long catetoryId = forumCategory.getId();
		User user = userEjb.getUserByUserId(userId);
		ForumCategory category = categorySingleton.getForumCategoryById(catetoryId);
		category.setOwner(user);
		processBusinessWithAuthorizationCheck(Constants.Action_UPDATE, category);
		this.getRequestMap().put("categoryowner", userId);
		this.getRequestMap().put("categoryName", category.getCategoryName());

		return Constants.NavSuccess;

	}

	@Override
	protected void processBusiness(String action, AbstractEntity entity) throws AuthorizationFailException {
		// TODO Auto-generated method stub
		ForumCategory category = (ForumCategory) entity;
		if (action.equalsIgnoreCase(Constants.Action_UPDATE)) {
			categorySingleton.updateForumCategory(category);
		}

	}

	/* -------------getter/setter----------------- */
}
